<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 1.创建对象字面量
        var dog1 = {
            name: '大黄',
            age: 3,
            speak: function () {
                console.log('wang wang')
            }
        }

        // 2.new Object()
        var dog2 = new Object()

        dog2.name = '大黄'
        dog2.age = 3

        dog2.speak = function () {
            console.log('wang wang')
        }

        // 3.构造函数
        function Dog (name, age) {
            this.name = name
            this.age = age
        }
        Dog.prototype.speak = function() {
            console.log('wang wang')
        }
        var dog3 = new Dog('大黄', 3)

        //4.Object.create
        var dog4 = Object.create(dog1)

        console.log(dog1.name + '' + dog1.age)
        dog1.speak()

        console.log(dog2.name + '' + dog2.age)
        dog2.speak()

        console.log(dog3.name + '' + dog3.age)
        dog3.speak()

        console.log(dog4.name + '' + dog4.age)
        dog4.speak()

        console.log(dog1)
        console.log(dog2)
        console.log(dog3)
        console.log(dog4)
    </script>
</body>
</html>